import { getUUIDToken } from "@/utils/uuidToken.js";
import axios from "axios";
import nProgress from "nprogress"; //引入进度条
import "nprogress/nprogress.css"; //引入进度条的样式

//获取仓库:存储数据
import store from "@/store";
const requests = axios.create({
  baseURL: "/api",
  timeout: 5000,
});

//请求拦截器
requests.interceptors.request.use((config) => {
  config.headers.userTempId = getUUIDToken();
  if(store.state.user.userInfo){
    config.headers.token= store.state.user.userToken
  }
  nProgress.start(); //进度条开始
  return config;
});
//响应拦截器
requests.interceptors.response.use(
  (res) => {
    nProgress.done(); //进度条结束
    return res.data;
  },
  (error) => {
    return Promise.reject(error);
  }
);

export default requests;
